<!DOCTYPE html>
<html>
	<head>
		<title>客户群组</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<!-- 所有的 css & js 资源 -->
		<link rel="stylesheet" href="../../static/kj/element-ui/theme-chalk/index.css">
		<link rel="stylesheet" href="../../static/sa.css"> 
		<script src="../../static/vue.min.js"></script>
		<script src="../../static/kj/element-ui/index.js"></script>
		<script src="../../static/jquery.min.js"></script>
		<script src="../../static/kj/layer/layer.js"></script>
		<script src="../../static/sa.js"></script>
		<script src="../../sa-resources/router.js"></script>
	</head>
	<body>
		<div class="vue-box" style="display: none;" :style="'display: block;'">
			<div class="c-panel">
				<!-- ------------- 检索参数 ------------- -->
				<div class="c-title">客户群组</div>
				<el-form>
					<div class="c-item">
						<label class="c-label">群组名称：</label>
						<el-input size="mini" v-model="p.group_name" placeholder="模糊查询"></el-input>
					</div>
					<div class="c-item">
						<label class="c-label">群组编号：</label>
						<el-input size="mini" v-model="p.group_bn" placeholder="模糊查询"></el-input>
					</div>
					<div class="c-item" style="min-width: 0px;">
						<el-button size="mini" type="primary" icon="el-icon-search" @click="p.page = 1; f5()">查询</el-button>
					</div>
					<br />
				</el-form>
				<!-- <div class="c-title">数据列表</div> -->
				<!-- ------------- 快捷按钮 ------------- -->
				<div class="fast-btn">
					<el-button size="mini" type="primary" icon="el-icon-plus" @click="add()">新增</el-button>
					<el-button size="mini" type="success" icon="el-icon-view" @click="getBySelect()">查看</el-button>
					<el-button size="mini" type="danger" icon="el-icon-delete" @click="deleteByIds()">删除</el-button>
					<el-button size="mini" type="warning" icon="el-icon-download" @click="sa.exportExcel()">导出</el-button>
					<el-button size="mini" type="info"  icon="el-icon-refresh"  @click="sa.f5()">重置</el-button>
				</div>
				<!-- ------------- 数据列表 ------------- -->
				<el-table class="data-table" ref="data-table" :data="dataList" size="small">
					<el-table-column type="selection" width="45px"></el-table-column>
					<el-table-column label="ID" prop="group_id" width="80px" > </el-table-column>
					<el-table-column label="群组名称" prop="group_name"> </el-table-column>
					<el-table-column label="群组编号" prop="group_bn"></el-table-column>
					<el-table-column label="创建于" prop="created_at"></el-table-column>
					<el-table-column label="状态">
						<template slot-scope="s">
							<el-switch v-model="s.row.is_active" :active-value="1" :inactive-value="0" inactive-color="#ff4949"></el-switch>
							<b style="color: green;" v-if="s.row.is_active == 1">正常</b>
							<b style="color: red;" v-if="s.row.is_active == 0">禁用</b>
						</template>
					</el-table-column>
					<el-table-column prop="address" label="操作">
						<template slot-scope="s">
							<el-button class="c-btn" type="success"  icon="el-icon-view" @click="get(s.row)">详情</el-button>
							<el-button class="c-btn" type="danger" icon="el-icon-delete" @click="del(s.row)">删除</el-button>
						</template>
					</el-table-column>
				</el-table>
				<!-- ------------- 分页 ------------- -->
				<div class="page-box">
					<el-pagination background
						layout="total, prev, pager, next, sizes, jumper" 
						:current-page.sync="p.page" 
						:page-size.sync="p.page_size" 
						:total="dataCount" 
						:page-sizes="[1, 10, 20, 30, 40, 50, 100]" 
						@current-change="f5(true)" 
						@size-change="f5(true)">
					</el-pagination>
				</div>
			</div>
			<!-- 给layer打一波广告 -->
			<!-- <div class="c-panel" style="background-color: rgba(0,0,0,0);">
				layer：<el-link type="primary" href="http://layer.layui.com/" target="_blank">
					一个可以让你想到即可做到的JavaScript弹窗（层）解决方案
				</el-link>
			</div> -->
		</div>
		<script type="text/javascript">
			var app = new Vue({
				el: '.vue-box',
				data: {
					p: {	// 查询参数 
						group_name: '',
						group_bn: '',
						page: 1,
						page_size: 10,
						type: 'CUSTOMER'
					},
					dataCount: 0,
					dataList: []
				},
				methods: {
					// 数据刷新
					f5: function() {
						sa.ajax(router.getGroupList, this.p, function(res){
							this.dataList = res.list;	// 数据  
							this.dataCount = res.total;		// 分页  
							sa.f5TableHeight();		// 刷新表格高度 
						}.bind(this), {type: 'get'});
					},
					// 查看
					get: function(data) {
						var str = '<div>';
						str += '<p>编号：' + data.group_bn + '</p>';
						str += '<p>群组名称：' + data.group_name + '</p>';
						str += '<p>当前状态：<b>' + (data.is_active == 1 ? '正常' : '禁用') + '</b></p>';
						str += '<p>创建时间：' + data.created_at + '</p>';
						str += '</div>';
						sa.alert(str);
					},
					// 查看 - 根据选中的
					getBySelect: function(data) {
						var selection = this.$refs['data-table'].selection;
						if(selection.length == 0) {
							return sa.msg('请选择一条数据')
						}
						this.get(selection[0]);
					},
					// 新增
					add: function(data) {
						sa.showIframe('新增数据', 'group-add.html?id=-1', '420px', '420px');
					},
					// 删除
					del: function(data) {
						if(data.is_system == 1){
							return sa.alert('此数据是维持系统正常运行的重要数据<p style="color: red;">已被锁定，不可删除</p>');
						}
						sa.confirm('是否删除，此操作不可撤销', function(){
							sa.ajax(router.deleteGroup,{group_id: data.group_id},function(res){
								sa.arrayDelete(app.dataList, data);
								sa.ok('删除成功');
								sa.f5TableHeight();		// 刷新表格高度 
							});
						});
					},
					// 批量删除
					deleteByIds: function() {
						// 获取选中元素的id列表
						let selection = this.$refs['data-table'].selection;
						let ids = sa.getArrayField(selection, 'id');
						if(selection.length == 0) {
							return sa.msg('请至少选择一条数据')
						}
						// 提交删除 
						sa.confirm('是否批量删除选中数据？此操作不可撤销', function() {
							sa.ajax2('/SysType/deleteByIds', {ids: ids.join(',')}, function(res) {
								sa.arrayDelete(this.dataList, selection);
								sa.ok('删除成功');
								sa.f5TableHeight();		// 刷新表格高度 
							}.bind(this))
						}.bind(this));
					},
				},
				created: function(){
					this.f5()
					sa.onInputEnter();		// 监听输入框的回车事件，执行查询  
				}
			})
			
		</script>
	</body>
</html>
